package com.example.administrator.yuejian23.Fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioGroup;

import com.example.administrator.yuejian23.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class ClubInfoFragment extends Fragment {


    private ImageView imageView;
    private RadioGroup radioGroup;
    private ClubCourseFragment clubCourseFragment;
    private ClubIntroFragment clubIntroductionFragment;
    private FragmentManager manager;
    private FragmentTransaction transaction;

    public ClubInfoFragment() {
        // Required empty public constructor
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        imageView= (ImageView) view.findViewById(R.id.imageView4);
        radioGroup= (RadioGroup) view.findViewById(R.id.radioGroup);
        //
        manager=getChildFragmentManager();
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

                switch (checkedId){

                    case R.id.radio_club_info:
                        clubIntroductionFragment=new ClubIntroFragment();
                        replace(clubIntroductionFragment);
                        break;
                    case R.id.radio_club_course:
                        clubCourseFragment=new ClubCourseFragment();
                        replace(clubCourseFragment);
                        break;
                }
            }
        });

        radioGroup.check(R.id.radio_club_info);
    }


    private void replace(Fragment fragment){
        transaction=manager.beginTransaction();
        transaction.replace(R.id.clubinfo_framelayout,fragment);
        transaction.commit();
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_club_info, container, false);
    }

}
